<?php

namespace App\Admin\Controllers;

use App\Models\Resume;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets\Box;
use Illuminate\Support\Str;
use App\Admin\Actions\BlindBoxAction\RefreshBlindBoxRate;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Support\Facades\Storage;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use App\Admin\Actions\Post\ImportPost;
use App\Admin\Actions\Post\FxPost;
use App\Admin\Actions\Post\DownloadPost;
use App\Admin\Actions\Post\FxPostDd;
use Carbon\Carbon;
use App\Exports\ResumeExport;
use Maatwebsite\Excel\Facades\Excel;

class ResumesController extends AdminController
{
    protected $title = '简历列表';
    

    protected function grid()
    {
        $grid = new Grid(new Resume());
	    $grid->disableExport();
	    $grid->column('mi_id', 'id');
	    $grid->column('name', '姓名');
	    $grid->column('post', '岗位名称');
	    $grid->column('scale', '团队规模');
	    $grid->column('has_team', '是否有带团队潜力');
	    $grid->column('has_overseas_experience', '是否有海外工作经历');
	    $grid->column('overseas_seniority', '海外工作年限');
	    $grid->column('certificate', '资质证书');
	    $grid->column('industry', '所在行业_简历解析');
	    $grid->column('ys', '友商经历');

	    $grid->column('created_at', '创建时间')->display(function () {
	    	return $this->created_at->toDatetimeString();
	    });

	    $this->gridTools($grid);
	   	$this->gridActions($grid);

	   	//$this->gridFilter($grid);
	   	
        return $grid;
    }

    protected function gridTools(Grid $grid)
    {
	    $grid->tools(function (Grid\Tools $tools) {
	    	$tools->append(new ImportPost());
	    	$tools->append(new FxPost());
	    	$tools->append(new DownloadPost());
	    });
    }
    

   	protected function gridActions(Grid $grid)
	{
		$grid->actions(function (Grid\Displayers\Actions $actions) {
			$actions->disableView();
			$actions->add(new FxPostDd());
			/*$actions->add(new NewsExamineNone());
			$actions->add(new NewsTranslate());
			$actions->add(new NewsBriefCreate());
			$actions->add(new NewsImageCheck());*/
			//$actions->add(new RefreshBlindBoxRate());
		});
	}

	 protected function gridFilter(Grid $grid)
    {
	    $grid->filter(function (Grid\Filter $filter) {
		    $filter->expand();
	    });
    }


    protected function detail($id)
    {
        $show = new Show(Resume::findOrFail($id));
        return $show;
    }
    
    protected function form()
    {
        $form = new Form(new Resume());


	    $form->text('name', '姓名');
	    $form->text('post', '岗位名称');
	    $form->text('scale', '团队规模');
	    $form->text('has_team', '是否有带团队潜力');
 		$form->textarea('content', '内容');
 		

        return $form;
    }


     public function export()
    {
    	  $time = Carbon::now()->toDateTimeString();
    	set_time_limit(0);
        ini_set('memory_limit', '128M');
        header('Content-Type: application/vnd.ms-execl');

      
        $obj = new ResumeExport();
        return  Excel::download($obj, '简历数据'.$time.'.xlsx');
    }
   
}
